//判断是否是闰年
function isLeapYear(year) {
	return(year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}

//判断每个月的天数
function getMonthDays(year, month) {
	return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] || (isLeapYear(year) ? 29 : 28);
}

//判断所选日期是第几周 传入时间对象
function getWeekNumber(y, m, d) {
	var now = new Date(y, m - 1, d),
		year = now.getFullYear(),
		month = now.getMonth(),
		days = now.getDate();
	//那一天是那一年中的第多少天
	for(var i = 0; i < month; i++) {
		days += getMonthDays(year, i);
	}
	//那一年第一天是星期几
	var yearFirstDay = new Date(year, 0, 1).getDay() || 7;
	var week = null;
	if(yearFirstDay == 1) {
		week = Math.ceil(days / 7);
	} else {
		days -= (7 - yearFirstDay + 1);
		week = Math.ceil(days / 7) + 1;
	}
	return week;
}

//对返回出来的日期对象进行处理"."
function dateToString(date) {
	var year = date.getFullYear()
	var mouth = (date.getMonth() + 1 > 9) ? date.getMonth() + 1 : "0" + (date.getMonth() + 1);
	var day = (date.getDate() > 9) ? date.getDate() : "0" + date.getDate();
	var result = mouth + "." + day
	return result
}

//对返回出来的日期对象进行处理"-"
function dateToString2(date) {
	var year = date.getFullYear()
	var mouth = (date.getMonth() + 1 > 9) ? date.getMonth() + 1 : "0" + (date.getMonth() + 1);
	var day = (date.getDate() > 9) ? date.getDate() : "0" + date.getDate();
	var result = year + "/" + mouth + "/" + day
	return result
}

//通过当前参传入的时间对象来判断这周的周一和周日（周一为一周的第一天）同时获得周五
function getFirstAndLastDay(time, type) {
	var nowTime = time.getTime();
	var day = time.getDay();
	var oneDayLong = 24 * 60 * 60 * 1000;
	if(day == 0) {
		var MondayTime = nowTime - 6 * oneDayLong;
		var SundayTime = nowTime;
		var FridayTime = nowTime - 2 * oneDayLong
	} else {
		var MondayTime = nowTime - (day - 1) * oneDayLong;
		var SundayTime = nowTime + (7 - day) * oneDayLong;
		var FridayTime = nowTime + (5 - day) * oneDayLong
	}

	if(type == "line") {
		var monday = dateToString2(new Date(MondayTime));
		var sunday = dateToString2(new Date(SundayTime));
		var friday = dateToString2(new Date(FridayTime));
	} else {
		var monday = dateToString(new Date(MondayTime));
		var sunday = dateToString(new Date(SundayTime));
		var friday = dateToString(new Date(FridayTime));
	}

	return { begin: monday, end: sunday, friday: friday }

}